import 'package:flutter/material.dart';

import 'HomePage/ui.dart';
import 'ParseMarkdown/parser.dart';


class GlobalSettings{

  // --------------------------------{ 设置部分 }--------------------------------
  static var FilePath = [
    {"CS61A":["assets/CS61A.md","assets/CS61A.md","assets/CS61A.md","assets/CS61A.md"]},
    {"CS61B":["assets/CS61B.md","assets/CS61B.md","assets/CS61B.md","assets/CS61B.md"]},
    {"CS61C":["assets/CS61C.md","assets/CS61C.md","assets/CS61C.md","assets/CS61C.md"]},
    {"CS61A":["assets/CS61A.md","assets/CS61A.md","assets/CS61A.md","assets/CS61A.md"]},
  ];

  static var FileSummary = [
    ["主页","时间线","CS61A课程1","额外课程"],
    ["主页","时间线","CS61B课程1","额外课程"],
    ["主页","时间线","CS61C课程1","额外课程"],
    ["主页","时间线","CS61A课程1","额外课程"],
  ];

  static var FileContent = [
    ["渲染页面A1","渲染页面A2","渲染页面A3","test"],
    ["渲染页面B1","渲染页面B2","渲染页面B3","test"],
    ["渲染页面C1","渲染页面C2","渲染页面C3","test"],
    ["渲染页面A1","渲染页面A2","渲染页面A3","test"],
  ];

  static var FileSummaryIcon = [
    [Icons.home,Icons.home,Icons.home,Icons.home],
    [Icons.home,Icons.home,Icons.home,Icons.home],
    [Icons.home,Icons.home,Icons.home,Icons.home],
    [Icons.home,Icons.home,Icons.home,Icons.home],
  ];


  // --------------------------------{ 解析部分 }--------------------------------

  static var  AppTabHead = FilePath.map((mapEntry) {
    String tabText = mapEntry.keys.first;
    return Tab(text: tabText);
  }).toList();

  static var Content = FilePath.asMap().entries.expand((entry) {
    final index = entry.key;
    final map = entry.value;
    final paths = map.values.first;
    final titles = FileContent[index];

    return paths.asMap().entries.map((e) {
      final i = e.key;
      final path = e.value;
      final title = titles[i];
      return MarkdownPage(parseFileString: path, title: title);
    });
  }).toList();

  static var Tab2ContentMapping = () {
    Map<int, int> map = {};
    int startIndex = 0;

    // 遍历 FileContent，index是tab索引，contentList是每个tab对应的内容列表
    for (int i = 0; i < FileContent.length; i++) {
      map[i] = startIndex;
      startIndex += FileContent[i].length; // 累加当前tab内容数量，更新下个tab起始索引
    }
    return map;
  }();

  static var AppTabContent = List.generate(
    Tab2ContentMapping.length,
    (index) => Content[Tab2ContentMapping[index]!],
  );

  static var DrawerContent = FileSummary.asMap().entries.map((entry) {
    int i = entry.key;
    List<String> titles = entry.value;
    List<IconData> icons = FileSummaryIcon[i];

    return List.generate(titles.length, (j) {
      return MenuItemInfo(icons[j], titles[j]);
    });
  }).toList();
}